<!DOCTYPE html>
<html>
<head>
    <script src="../build/react.js"></script>
    <script src="../build/react-dom.js"></script>
    <script src="../build/browser.min.js"></script>
</head>
<body>
<div id="example"></div>
<script type="text/babel">

    class Clock extends React.Component {
        constructor(props) {
            super(props);
            this.state = {date: new Date()};
        }

        componentDidMount() {
            this.timer = setInterval(
                ()=>(this.setState({
                        date: new Date()
                    })),
                1000
            );
        }

        componentWillUnmount() {
            clearInterval(this.timer);
        }

        render() {
            return (
                    <div>
                        <h1>Hello, world!</h1>
                        <h2>It is {this.state.date.toLocaleTimeString()}.</h2>
                    </div>
            );
        }
    }

    ReactDOM.render(
        <Clock/>,
        document.getElementById('example')
    )
</script>
</body>
</html>

